package ru.xpparty.scanner;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

/**
 * POJOs result of scanning process
 * 
 * @author xp.party
 * 
 */
public class ScanResult {
	private String host;
	private Map<Integer, PortStatus> statuses = new LinkedHashMap<Integer, PortStatus>();

	/**
	 * Constructs new scan result for given host
	 * 
	 * @param host
	 *            given host to scan
	 */
	public ScanResult(String host) {
		this.host = host;
	}

	/**
	 * Appends information about status of given port in final report
	 * 
	 * @param port
	 *            given port
	 * @param status
	 *            status of given port
	 */
	public void append(int port, PortStatus status) {
		statuses.put(port, status);
	}

	/**
	 * @param portNumber
	 *            number of port to check
	 * @return status of port with given <code>portNumber</code>
	 * 
	 */
	public PortStatus getStatus(int portNumber) {
		return statuses.get(portNumber);
	}

	@Override
	public String toString() {
		StringBuffer report = new StringBuffer();
		for (Integer port : statuses.keySet()) {
			report.append(host).append(":").append(port).append(" > ")
					.append(statuses.get(port)).append("\n");
		}
		return report.toString();
	}
}
